home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / MINIHELP.PAK / MINIHELP.C < prev    next >
C/C++ Source or Header  |  1997-05-06  |  8KB  |  296 lines

  1. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF 
  2. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO 
  3. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 
  4. // PARTICULAR PURPOSE.
  5. //
  6. // Copyright (C) 1993-1995  Microsoft Corporation.  All Rights Reserved.
  7. //
  8. //  MODULE: minihelp.c
  9. //
  10. //  PURPOSE: Implements commands in the help menu.
  11. //
  12. //   
  13. //  FUNCTIONS:
  14. //    WndProc - Processes messages for the main window.
  15. //    MsgCommand - Handle the WM_COMMAND messages for the main window.
  16. //    MsgDestroy - Handles the WM_DESTROY message by calling 
  17. //                 PostQuitMessage().
  18. //    CmdExit - Handles the file exit command by calling destory 
  19. //              window on the main window.
  20. //    CmdHelpContents - Displays the help contents for the sample.
  21. //    CmdHelpSearch - Displays the help index for the sample.
  22. //    CmdHelpHelp - Displays the help on help.
  23. //
  24. //   
  25. //  COMMENTS:
  26. //    Message dispatch table -
  27. //      For every message to be handled by the main window procedure
  28. //      place the message number and handler function pointer in
  29. //      rgmsd (the message dispatch table).  Place the prototype
  30. //      for the function in globals.h and the definition of the
  31. //      function in the appropriate module.
  32. //    Command dispatch table -
  33. //      For every command to be handled by the main window procedure
  34. //      place the command number and handler function pointer in
  35. //      rgcmd (the command dispatch table).  Place the prototype
  36. //      for the function in globals.h and the definition of the
  37. //      function in the appropriate module.
  38. //    Globals.h Contains the definitions of the structures and dispatch.c
  39. //      contains the functions that use these structures.
  40. //      
  41. //  SPECIAL INSTRUCTIONS: N/A
  42. //   
  43.  
  44. #include <windows.h>            // required for all Windows applications
  45. #include <windowsx.h>
  46. #ifdef WIN16
  47. #include "win16ext.h"           // required only for win16 applications
  48. #endif
  49. #include "globals.h"            // prototypes specific to this application
  50. #include "resource.h"
  51.  
  52.  
  53. // Main window message table definition.
  54. MSD rgmsd[] =
  55. {
  56.     {WM_COMMAND, MsgCommand},
  57.     {WM_DESTROY, MsgDestroy}
  58. };
  59.  
  60. MSDI msdiMain =
  61. {
  62.     sizeof(rgmsd) / sizeof(MSD),
  63.     rgmsd,
  64.     edwpWindow
  65. };
  66.  
  67.  
  68. // Main window command table definition.
  69. CMD rgcmd[] =
  70. {
  71.     {IDM_HELPCONTENTS,  CmdHelpContents},
  72.     {IDM_HELPSEARCH,    CmdHelpSearch},
  73.     {IDM_HELPHELP,      CmdHelpHelp},
  74.     {IDM_EXIT,          CmdExit},
  75.     {IDM_ABOUT,         CmdAbout}
  76. };
  77.  
  78. CMDI cmdiMain =
  79. {
  80.     sizeof(rgcmd) / sizeof(CMD),
  81.     rgcmd,
  82.     edwpWindow
  83. };
  84.  
  85.  
  86. //
  87. //  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
  88. //
  89. //  PURPOSE:  Processes messages for the main window.
  90. //
  91. //  PARAMETERS:
  92. //    hwnd     - window handle
  93. //    uMessage - message number
  94. //    wparam   - additional information (dependant on message number)
  95. //    lparam   - additional information (dependant on message number)
  96. //
  97. //  RETURN VALUE:
  98. //    The return value depends on the message number.  If the message
  99. //    is implemented in the message dispatch table, the return value is
  100. //    the value returned by the message handling function.  Otherwise,
  101. //    the return value is the value returned by the default window procedure.
  102. //
  103. //  COMMENTS:
  104. //    Call the DispMessage() function with the main window's message dispatch
  105. //    information (msdiMain) and the message specific information.
  106. //
  107.  
  108. LRESULT CALLBACK WndProc(HWND   hwnd, 
  109.                          UINT   uMessage, 
  110.                          WPARAM wparam, 
  111.                          LPARAM lparam)
  112. {
  113.     return DispMessage(&msdiMain, hwnd, uMessage, wparam, lparam);
  114. }
  115.  
  116.  
  117. //
  118. //  FUNCTION: MsgCommand(HWND, UINT, WPARAM, LPARAM)
  119. //
  120. //  PURPOSE: Handle the WM_COMMAND messages for the main window.
  121. //
  122. //  PARAMETERS:
  123. //    hwnd     - window handle
  124. //    uMessage - WM_COMMAND (Unused)
  125. //    GET_WM_COMMAND_ID(wparam,lparam)   - Command identifier
  126. //    GET_WM_COMMAND_HWND(wparam,lparam) - Control handle
  127. //
  128. //  RETURN VALUE:
  129. //    The return value depends on the message number.  If the message
  130. //    is implemented in the message dispatch table, the return value is
  131. //    the value returned by the message handling function.  Otherwise,
  132. //    the return value is the value returned by the default window procedure.
  133. //
  134. //  COMMENTS:
  135. //    Call the DispCommand() function with the main window's command dispatch
  136. //    information (cmdiMain) and the command specific information.
  137. //
  138.  
  139. #pragma argsused
  140. LRESULT MsgCommand(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
  141. {
  142.     return DispCommand(&cmdiMain, hwnd, wparam, lparam);
  143. }
  144.  
  145.  
  146. //
  147. //  FUNCTION: MsgDestroy(HWND, UINT, WPARAM, LPARAM)
  148. //
  149. //  PURPOSE: Calls PostQuitMessage().
  150. //
  151. //  PARAMETERS:
  152. //
  153. //    hwnd      - Window handle  (Unused)
  154. //    uMessage  - Message number (Unused)
  155. //    wparam    - Extra data     (Unused)
  156. //    lparam    - Extra data     (Unused)
  157. //
  158. //  RETURN VALUE:
  159. //
  160. //    Always returns 0 - Message handled
  161. //
  162. //  COMMENTS:
  163. //
  164. //
  165.  
  166. #pragma argsused
  167. LRESULT MsgDestroy(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
  168. {
  169.      PostQuitMessage(0);
  170.      return 0;
  171. }
  172.  
  173. //
  174. //  FUNCTION: CmdExit(HWND, WORD, WORD, HWND)
  175. //
  176. //  PURPOSE: Exit the application.
  177. //
  178. //  PARAMETERS:
  179. //    hwnd     - The window.
  180. //    wCommand - IDM_EXIT (unused)
  181. //    wNotify  - Notification number (unused)
  182. //    hwndCtrl - NULL (unused)
  183. //
  184. //  RETURN VALUE:
  185. //    Always returns 0 - command handled.
  186. //
  187. //  COMMENTS:
  188. //
  189. //
  190.  
  191. #pragma argsused
  192. LRESULT CmdExit(HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
  193. {
  194.      DestroyWindow(hwnd);
  195.     return 0;
  196. }
  197.  
  198.  
  199. //
  200. //  FUNCTION: CmdHelpContents(HWND, WORD, WORD, HWND)
  201. //
  202. //  PURPOSE: Displays the help contents for the sample.
  203. //
  204. //  PARAMETERS:
  205. //    hwnd - The window handle
  206. //    wCommand - IDM_HELPCONTENTS (unused)
  207. //    wNotify   - Notification number (unused)
  208. //    hwndCtrl - NULL (unused)
  209. //
  210. //  RETURN VALUE:
  211. //    Always returns 0 - Message handled
  212. //
  213. //  COMMENTS:
  214. //
  215. //
  216.  
  217. #pragma argsused
  218. LRESULT CmdHelpContents(HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
  219. {
  220.      if (!WinHelp (hwnd, SZAPPNAME ".HLP", HELP_KEY,(DWORD)(LPSTR)"CONTENTS"))
  221.      {
  222.           MessageBox(GetFocus(),
  223.                          "Unable to activate help",
  224.                          szAppName,
  225.                          MB_SYSTEMMODAL|MB_OK|MB_ICONHAND);
  226.      }
  227.  
  228.     return 0;
  229. }
  230.  
  231.  
  232. //
  233. //  FUNCTION: CmdHelpSearch(HWND, WORD, WORD, HWND)
  234. //
  235. //  PURPOSE: Displays the help index for the sample.
  236. //
  237. //  PARAMETERS:
  238. //    hwnd - The window handle
  239. //    wCommand - IDM_HELPSEARCH (unused)
  240. //    wNotify   - Notification number (unused)
  241. //    hwndCtrl - NULL (unused)
  242. //
  243. //  RETURN VALUE:
  244. //    Always returns 0 - Message handled
  245. //
  246. //  COMMENTS:
  247. //
  248. //
  249.  
  250. #pragma argsused
  251. LRESULT CmdHelpSearch(HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
  252. {
  253.      if (!WinHelp(hwnd, SZAPPNAME ".HLP", HELP_PARTIALKEY, (DWORD)(LPSTR)""))
  254.      {
  255.           MessageBox(GetFocus(),
  256.                          "Unable to activate help",
  257.                          szAppName,
  258.                          MB_SYSTEMMODAL|MB_OK|MB_ICONHAND);
  259.     }
  260.  
  261.     return 0;
  262. }
  263.  
  264.  
  265. //
  266. //  FUNCTION: CmdHelpHelp(HWND, WORD, WORD, HWND)
  267. //
  268. //  PURPOSE: Displays the help on help.
  269. //
  270. //  PARAMETERS:
  271. //    hwnd - The window handle
  272. //    wCommand - IDM_HELPHELP (unused)
  273. //    wNotify   - Notification number (unused)
  274. //    hwndCtrl - NULL (unused)
  275. //
  276. //  RETURN VALUE:
  277. //    Always returns 0 - Message handled
  278. //
  279. //  COMMENTS:
  280. //
  281. //
  282.  
  283. #pragma argsused
  284. LRESULT CmdHelpHelp(HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
  285. {
  286.      if(!WinHelp(hwnd,NULL, HELP_HELPONHELP, 0))
  287.      {
  288.           MessageBox(GetFocus(),
  289.                           "Unable to activate help",
  290.                           szAppName,
  291.                     MB_SYSTEMMODAL|MB_OK|MB_ICONHAND);
  292.     }
  293.  
  294.     return 0;
  295. }
  296.